package com.hightemperator.controller;

import com.hightemperator.po.Assist;
import com.hightemperator.po.Commend;
import com.hightemperator.service.CircleService;
import com.hightemperator.util.LocalResponseBody;
import com.hightemperator.util.getOfToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/circle")
public class CircleController {

    @Autowired
    public CircleService circleService;


    /**
     * 点赞
     * @param assist
     * @return
     */
    @RequestMapping("addAssist")
    public LocalResponseBody addAssist(HttpServletRequest request,
                                       Assist assist){

        String token = request.getParameter("token");
        Integer uId = getOfToken.getUserMessageString(token, request);
        assist.setUserid(uId);

        int successCode = circleService.updateAssist(assist);
        if (successCode == 0){
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }

    /**
     * 添加评论
     * @param commend
     * @return
     */
    @RequestMapping("addCommend")
    public LocalResponseBody addCommend(Commend commend){
        int successCode = circleService.addCommend(commend);
        if (successCode == 0){
            return new LocalResponseBody("操作失败").doFail();
        }
        return new LocalResponseBody("操作成功").doSuccess();
    }

    /**
     * 点赞列表（显示头像）
     * @param circleId
     * @return
     */
    @RequestMapping("getAssistList")
    public LocalResponseBody getAssistList(@RequestParam(value = "circleId") Integer circleId){
        return new LocalResponseBody("操作成功").doSuccess(circleService.getAssistList(circleId));
    }



    /**
     * 评论列表（显示头像）
     * @param circleId
     * @return
     */
    @RequestMapping("getCommendList")
    public LocalResponseBody getCommendList(HttpServletRequest request,
            @RequestParam(value = "circleId") Integer circleId){
        String token = request.getParameter("token");
        Integer uId = getOfToken.getUserMessageString(token, request);
        return new LocalResponseBody("操作成功").doSuccess(circleService.getCommendList(circleId,uId));
    }

}